Skip to content

Conversation

viniciusdsmello
Copy link
Contributor

@viniciusdsmello viniciusdsmello commented Oct 14, 2025

Pull Request

Summary

This PR adds comprehensive tracing support for OpenAI's new Responses API (client.responses.create) while maintaining full backward compatibility with the existing Chat Completions API (client.chat.completions.create).

Changes

  • Updated trace_openai and trace_async_openai to dynamically detect and patch the responses.create endpoint.
  • Implemented new handler functions for both streaming and non-streaming Responses API calls (sync and async).
  • Added helper functions for Responses API-specific parameter mapping, output parsing, streaming chunk extraction, and usage data extraction.
  • Modified add_to_trace to differentiate between Chat Completions and Responses API calls for improved trace naming and metadata.
  • Created a comprehensive example (examples/tracing/openai/responses_api_example.py) demonstrating usage for both APIs, including streaming and function calling.

Context

OpenAI's Responses API unifies multiple capabilities (chat, text, tool use, JSON mode) into a single interface, providing improved metadata structure and traceability. This update extends Openlayer's tracing logic to support this new, more aligned endpoint, ensuring that users can leverage the latest OpenAI features with full observability without breaking existing integrations.

Testing

  • Unit tests (comprehensive test suites verifying backward compatibility and new Responses API features for both sync and async clients)
  • Manual testing (verified functionality using the new example script)
  • Postman CI/CD
  • Other (please specify)

Integrates tracing for the new OpenAI Responses API, maintaining backward compatibility with the Chat Completions API. This includes support for both synchronous and asynchronous clients, streaming, and function calling.

Co-authored-by: vinicius <vinicius@openlayer.com>
Copy link

cursor bot commented Oct 14, 2025

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

viniciusdsmello and others added 7 commits October 14, 2025 16:41
Co-authored-by: vinicius <vinicius@openlayer.com>
Improves the handling of the Responses API output structure by adding checks for various content formats and updating the extraction of token usage to accommodate changes in attribute names. This ensures better compatibility with different response formats while maintaining existing functionality.
… github.com:openlayer-ai/openlayer-python into cursor/update-openai-tracing-for-responses-api-58e5
@viniciusdsmello viniciusdsmello changed the title Update openai tracing for responses api [OPEN-7543] Update OpenAI Wrapper to support Responses API Oct 15, 2025
@viniciusdsmello viniciusdsmello marked this pull request as ready for review October 15, 2025 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants